package gui.controller;

import gui.view.MaxSolutionsChoiceBox;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class MaxSolutionsListener implements ChangeListener {

	private MaxSolutionsChoiceBox box;
	private Object oldValue = new Object();
	private PropertyChangeSupport support;

	public MaxSolutionsListener(MaxSolutionsChoiceBox maxSolutionsChoiceBox) {
		this.box = maxSolutionsChoiceBox;
		this.support = new PropertyChangeSupport(this.box);
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		this.support.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		this.support.removePropertyChangeListener(listener);
	}

	@Override
	public void stateChanged(ChangeEvent arg0) {
		this.support.firePropertyChange(PropertyChangeConstants.MAXSOLUTIONS
				.toString(), this.oldValue, this.box.getValue());
		this.oldValue = this.box.getValue();
	}

}
